import { UsernameRequest } from '@interface/login'
import { useUserStore } from '@store/useUserstore'
import { userMunStron } from '@store/userMunStore'
import { ElMessage } from 'element-plus'
import router from '@router'
const userLogin = async (res: UsernameRequest) => {
  // 判断是否登陆成功
  if (res.code != '200') return ElMessage.error(res.msg)
  const token = res.data
  // 持久化存储token
  localStorage.setItem('token', token || '')
  // 获取用户信息
  await useUserStore().Getinfo()
  // 获取路由信息
  await userMunStron().getmuns()
  //跳转后台管理系统首页
  router.push({ path: '/' })
  return
}

export default userLogin
